package com.zm.cc.web;

import com.zm.cc.Result;
import com.zm.cc.Utils;
import com.zm.cc.entity.Fav;
import com.zm.cc.entity.User;
import com.zm.cc.service.BizException;
import com.zm.cc.service.IFavService;
import org.springframework.context.ApplicationContext;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/delFav")
public class DelFavServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Integer id = Integer.valueOf(req.getParameter("id"));
        Fav fav = new Fav();
        fav.setId(id);
        Result result = new Result();

        ApplicationContext cxt = (ApplicationContext) this.getServletContext().getAttribute("cxt");
        IFavService dao = cxt.getBean(IFavService.class);

        int i = dao.deleteFav(fav);
        if (i<=0){
            result.setCode(-1);
            result.setMsg("删除失败");
            Utils.print(resp,result);
            return;
        }
        result.setCode(1);
        result.setMsg("删除成功");
        Utils.print(resp,result);
    }
}
